package cc.sheji.util;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import okhttp3.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.IOException;

@Component
public class EncoderUtil {

    String key = "1234567891011123";
    SymmetricCrypto aes;

    @PostConstruct
    public void init() {
        // 生成密钥
        byte[] byteKey = SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue(), key.getBytes()).getEncoded();
        aes = SecureUtil.aes(byteKey);
//        String content = "明文";
//        // 加密
//        String encryptData = aes.encryptBase64(content);
//        System.out.println(encryptData);
//        // nuP9GXvHgzW6Q12notB8jQ==
//
//        // 解密
//        String decryptData = aes.decryptStr(encryptData);
//        System.out.println(decryptData);

    }

    public String encodeStr(String content) {
        String encryptData = aes.encryptBase64(content);
        return encryptData;
    }

}
